
package com.oahc.magicdefender.util;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData;

public class FontHelper {

    private static FontHelper inFontHelper;

    public static FontHelper getInstance() {
        if (inFontHelper == null) {
            inFontHelper = new FontHelper();
        }
        return inFontHelper;
    }

    BitmapFont font;

    public FontHelper() {

        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
                Gdx.files.internal("font/font.ttf"));
        FreeTypeBitmapFontData fontData = generator.generateData(40,
                FreeTypeFontGenerator.DEFAULT_CHARS, false);
        font = new BitmapFont(fontData, fontData.getTextureRegions()[0], false);

        Gdx.app.log("MD", "init FontHelper");
    }

    public void drawText(SpriteBatch spriteBatch, String text, float x, float y) {
        font.setColor(Color.BLACK);
        font.draw(spriteBatch, text, x, y);
        font.setColor(Color.WHITE);
        font.draw(spriteBatch, text, x - 5, y + 5);
    }

    public void drawFPS(SpriteBatch spriteBatch) {
        font.draw(spriteBatch, "Fps:" + Gdx.graphics.getFramesPerSecond(), 20, 50);
    }

    public static void clearInstance() {
        inFontHelper = null;
    }

}
